#include <iostream>

using std::cout;
using std::endl;

class Point {
public:
    Point() 
    : _ix(0)
    , _iy(0)
    {
        cout << "Point()" << endl;
    }

    Point(int ix, int iy)
    : _ix(ix)
    , _iy(iy)
    {
        cout <<"Point(int,int)" << endl;
    }

    ~Point() {  cout <<"~Point()" << endl;  }

    void print() 
    {
        cout << "(" << _ix 
             << "," << _iy
             << ")";
    }

private:
    int _ix;
    int _iy;
};

class Line {
public:
    //在Line的默认构造函数中，会自动调用对象成员Point类型的默认构造函数
    Line() {
        cout << "Line()" << endl;
    }

    Line(int x1, int y1, int x2, int y2)
    : _pt1(x1, y1)   //在Line的有参构造函数中，调用Point类型的有参构造函数
    , _pt2(x2, y2)   //如果不这样写，只会调用Point的默认构造函数
    {
        cout << "Line(int,int,int,int)" << endl;
    }

    void print()
    {
        _pt1.print();
        cout << " --> ";
        _pt2.print();
        cout << endl;
    }

    ~Line() {
        cout << "~Line()" << endl;
    }

private:
    Point _pt1;
    Point _pt2;
};

int main()
{
    Line line;
    line.print();
    cout << endl;

    Line line2(1, 2, 3, 4);
    line2.print();

    return 0;
}

